package com.atguigu.yygh.task.schedule;

import com.atguigu.yygh.rabbit.RabbitService;
import com.atguigu.yygh.rabbit.constant.MqConst;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling   //开启定时任务
public class ScheduledTask {

    @Autowired
    private RabbitService rabbitService;

    //定时任务执行的方法
    //每天晚上八点执行 20 点
    // 0 0 20 * * ？
    //cron表达式设置执行规则
//    @Scheduled(cron = "0 0 20 * * ?")
    @Scheduled(cron = "0/10 * * * * ?")
    public void taskTip(){
        //发送mq消息，传递参数：查询日期
        //查询日期 第二天日期
        DateTime dateTime = new DateTime().plusDays(1);
        //年-月-日 字符串
        String dateString = dateTime.toString("yyyy-MM-dd");

        //调用方法发送mq消息
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,
                MqConst.ROUTING_TASK_8,dateString);
    }
}
